<?php
// 列出目录下的所有目录
// 只列出一级
function list_folder($location = '/', $type = '*')
{
    $dirs = array();
    if ($handle = opendir($location)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $dirs[] = $file;
            }
        }
        closedir($handle);
    }
    // 再根据文件后缀名进行过滤
    //如果type不等于*或者不为空则开始过滤
    if ($type != '*' && $type != '') {
        $dirs = array_filter($dirs, function($item) use ($type) {
            return strpos($item, $type) !== false;
        });
    }


    return $dirs;
}

// 示例调用
//$location = 'E:/site/athlon_erp/uploadfiles/craft2tiangong';
//$type = '.jpg';
//$result = list_folder($location, $type);
//print_r($result);
?>
